package edu.sju.chenshu.common.core.service;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import edu.sju.chenshu.common.core.domain.Result;
import edu.sju.chenshu.common.core.domain.TableDataInfo;

import java.util.List;

public interface BaseService {

    public default Result<Void> toResult(int rows) {
        return rows > 0 ? Result.ok() : Result.fail();
    }

    public default Result<Void> toResult(boolean result) {
        return result ? Result.ok() : Result.fail();
    }

    public default TableDataInfo getTableDataInfo(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return  TableDataInfo.empty();
        }
        long total = new PageInfo<>(list).getTotal(); //获取符合查询条件数据的总数
        return TableDataInfo.success(list, total);
    }
}
